<template>
  <page-wrap back hide-tab title="职业搜索" stay-still :bg-color="uNavColor" >
    <InterViewNavbg/>
    <view>
      <view class="search">
        <u-search
          placeholder="请输入职业"
          class="library-u-search"
          v-model="keyword"
          height="80"
          bg-color="#FFFFFF;"
          maxlength="20"
          :show-action="true"
          :clearabled="false"
          @search="handleSearch"
          @custom="handleSearch"
        ></u-search>
      </view>
      <scroll-view
        class="scrollView"
        scroll-y
        enable-flex
        @scrolltolower="loadMore"
        :refresher-triggered="triggered"
      >
        <view class="allContaienr" @click="clickCell(item)" v-for="(item, index) in list" :key="index">
          <text class="itemName">{{ item.ylPositionName }}</text>
        </view>
        <u-loadmore
          v-if="list.length > 0 || !loaded"
          class="list-more"
          :status="moreLoading"
          :load-text="loadText"
        />
        <Empty
          v-if="loaded && list.length <= 0"
          :baseImg="emptyImg"
          text="暂无数据"
          :fontWeight="400"
        />
      </scroll-view>
    </view>
  </page-wrap>
</template>

<script>
import Empty from "@/components/Empty.vue";
import InterviewCell from "./components/InterviewCell.vue";
import { getCompanyInterviewSearch } from "@/api/modules/company";
import InterViewNavbg from "./components/InterViewNavbg.vue";
export default {
  components: {
    Empty,
    InterviewCell,
    InterViewNavbg
  },
  data() {
    return {
      shareShow: false,
      keyword: "",
      list: [
        // {
        //   ylPositionId: 1233,
        //   ylPositionName: "java开发工程师",
        // },
      ],

      pageParams: {
        pageNo: 1,
        pageSize: 10,
      },
      emptyImg: this.$imgBaseSelf + "common/empty.png",
      searchIcon: this.$imgBaseSelf + "common/search.png",
      finished: false,
      loading: false,
      moreLoading: "loadmore",
      loadText: {
        loadmore: "加载更多",
        loading: "加载中",
        nomore: "已经到底啦",
      },
      loaded: false,
    };
  },
  mounted() {
    this.getData(false);
  },
  methods: {
    loadMore() {
      this.getData(true);
    },
    onRestore() {
      this.triggered = false;
      this._triggered = false;
    },
    onRefresh() {
      if (this._triggered) return;
      this._triggered = true;

      if (!this.triggered) {
        this.triggered = true;
      }
      this.getData(false);
    },
    getData(isMore) {
      if (this.moreLoading == "loading") return;
      if (this.moreLoading == "nomore" && isMore) {
        return;
      }
      if (!isMore) {
        // 刷新数据
        this.pageParams.pageNo = 1;
      }
      const params = {
        positionName: this.keyword,
        pageNo: this.pageParams.pageNo,
        pageSize: this.pageParams.pageSize,
      };
      this.moreLoading = "loading";
      console.log(params);
      getCompanyInterviewSearch(params)
        .then((res) => {
          this.moreLoading = "loadmore";
          this.loaded = true;
          console.log(res);
          if (res.code == 200) {
            if (isMore) {
              this.list.push(...res.data);
            } else {
              this.list = res.data;
            }
            this.pageParams.pageNo++;
            if (this.pageParams.pageNo > res.pageparam.pages) {
              this.moreLoading = "nomore";
            }
          } else {
            this.moreLoading = "nomore";
            uni.showToast({
              title: res.status_desc,
              icon: "none",
            });
          }
        })
        .catch((e) => {
          console.log(e);
          this.moreLoading = "nomore";
        })
        .finally(() => {
          this.triggered = false;
          this._triggered = false;
        });
    },
    handleSearch(value) {
      this.keyword = value;
      this.getData(false);
    },

    clickCell(item) {
      const pages = getCurrentPages()
      const prevPage = pages[pages.length - 2]
      prevPage.setData({
        resultData: item,
      })
      uni.navigateBack();
    },
  },
};
</script>

<style lang="scss" scoped>
.search {
  margin: 32rpx 32rpx 10rpx;
}

.scrollView {
  box-sizing: border-box;
  height: calc(100vh - 220rpx);
}


.allContaienr {
  background: white;
  border-radius: 32rpx;
  justify-content: space-between;
  flex-direction: row;
  padding: 32rpx;
  margin: 32rpx;
  align-items: center;
  .itemName {
    font-size: 16px;
    color: #222222;
  }
}
</style>
